package com.sx.micowell.framework.model

import androidx.lifecycle.MutableLiveData
import com.example.mvvm.base.data.MutableLiveListData
import com.example.mvvm.base.vm.BaseViewModel
import com.github.mikephil.charting.data.Entry
import com.miloyu.modelnet.network.ApiResponse
import com.miloyu.modelnet.network.HttpClient
import com.miloyu.modelnet.network.service.IApiService
import com.miloyu.modelnet.network.tools.RxUtils
import com.miloyu.modelnet.response.AppBanner
import com.miloyu.modelnet.response.LastWeekSport
import com.miloyu.modelnet.response.LastWeekSportInfo
import com.miloyu.modelnet.response.getUrl

/**
 * @Description
 * @Author 梁浩文
 * @Date 2021/9/14 16:11
 */
class SportEndModel : BaseViewModel() {


    var calories = MutableLiveData<String>("0")

    var time = MutableLiveData<String>("0")

    //获取训练结束背景
    var imageUrl = MutableLiveData<String>()

    var lastWeekList = MutableLiveListData <LastWeekSportInfo >()

    //获取趋势图
    fun getSportLastWeek() {
        HttpClient.instance.create(IApiService::class.java)
            .getLastWeekSport()
            .compose(RxUtils.compose())
            .subscribe(object : ApiResponse<LastWeekSport>() {
                override fun success(data: LastWeekSport?, msg: String?) {
                    data?.let {
                        lastWeekList.postValue(it.info)

                    }
                }

                override fun onFail(e: Throwable?, errorMsg: String?) {

                }

            })
    }

    fun getSportEnd() {
        HttpClient.instance.create(IApiService::class.java)
            .getSportEndVideo()
            .compose(RxUtils.compose())
            .doOnSubscribe { ui.showDialog() }
            .subscribe(object : ApiResponse<AppBanner>() {
                override fun success(data: AppBanner?, msg: String?) {
                    imageUrl.postValue(data?.info?.url?.getUrl())
                    ui.hideDialog()
                }

                override fun onFail(e: Throwable?, errorMsg: String?) {
                    ui.hideDialog()
                }
            })
    }
}